<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title></title>
    <meta name="renderer" content="webkit"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all"/>
    <style>
        .layui-form-item .layui-input-inline {
            width: 150px;
        }
        .layui-form-label {
            padding: 9px 5px;
            width: auto;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        {include file="live_store/tab_nav" /}

        <form class="layui-form" action=""  id="sbumitForm">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">商品名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="title" placeholder="商品名称"  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline ">
                        <label class="layui-form-label">商品类型</label>
                        <div class="layui-input-inline" style="width: 110px">
                            <select name="type">
                                <option value="">全部</option>
                                <option value="1">虚物</option>
                                <option value="2">实物</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline ">
                        <label class="layui-form-label">价格类型</label>
                        <div class="layui-input-inline" style="width: 110px">
                            <select name="price_type">
                                <option value="">全部</option>
                                <option value="1">宝石</option>
                                <option value="2">钻石</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">筛选时间</label>
                        <div class="layui-input-inline">
                            <input type="text" name="start_time"  id="start_time" placeholder="开始时间" autocomplete="off" class="layui-input" readonly style="width: 155px;display: inline">
                        </div>
                    </div>
                    <div class="layui-inline" style="padding-left: 0px;padding-right: 0px;">
                        至
                    </div>

                    <div class="layui-inline">
                        <div class="layui-input-inline" id="end_time_div">
                            <input type="text" name="end_time" id="end_time"  placeholder="结束时间" autocomplete="off" class="layui-input" readonly style="width: 155px;display: inline">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <div class="layui-btn" id="FormSubmit">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </div>
                    </div>
                </div>
            </div>
        </form>
        <div class="layui-card-body">
            <table id="demo" lay-filter="test"></table>
        </div>
    </div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: "/layuiadmin/", //静态资源所在路径
    }).extend({
        index: "lib/index", //主入口模块
    }).use(["table", "laydate"], function () {
        $ = layui.jquery, form = layui.form, table = layui.table, laydate = layui.laydate;;

        table.render(table_conf());

        $("#FormSubmit").click(function () {
            table.render(table_conf());
        });

        $(this).removeAttr("lay-key");
        laydate.render({
            elem: '#start_time', //指定元素
            trigger: 'click',
            max: '<?php echo date("Y-m-d");?>',
            done: function (value, date, endDate) {
                $("#end_time_div").empty();
                $("#end_time_div").append('<input type="text" name="end_time" id="end_time"  placeholder="结束时间" autocomplete="off" class="layui-input" readonly style="width: 155px;display: inline">');
                laydate.render({
                    elem: '#end_time', //指定元素
                    trigger: 'click',
                    min: value,
                    max: '<?php echo date("Y-m-d");?>',
                });
            },
        });

        laydate.render({
            elem: '#end_time', //指定元素
            trigger: 'click',
            max: '<?php echo date("Y-m-d");?>',
        })

    });

    function table_conf() {
        return {
            elem: '#demo',
            id: '#demo',
            url: '/admin/live_store/order?' + $("#sbumitForm").serialize(),
            defaultToolbar: [
                'filter', 'print', {title: '提示', layEvent: 'LAYTABLE_EXCEL', icon: 'layui-icon-table'},
            ],
            page: {
                curr: 1   //默认从第一页开始搜索
            },
            method: "get",
            //where: $("#sbumitForm").serialize(),
            limit: 20,
            limits: [20, 30, 50, 100],
            text: {
                none: '暂无相关数据！'//默认无数据
            },
            response: {
                statusName: 'code',
                statusCode: 0,
                msgName: 'msg',
                countName: 'count',
                dataName: 'list',
            },
            cols: [[ //表头
                {field: 'id', title: 'ID', width: "80", align: "center",},
                {field: 'uid', title: '用户ID', width: "100", align: "center",},
                {field: 'order_no', title: '流水码号', width: "170", align: "center",},
                {field: 'title', title: '商品名称', width: "120", align: "center"},
                {field: '', title: '商品类型', width: "100", align: "center", templet: function (item) {
                        if (item.type == 1) {
                            return '虚物';
                        }

                        return '实物';
                    }
                },
                {field: 'ship_num', title: '商品数量', width: "90", align: "center"},
                {field: '', title: '贵族折扣', width: "90", align: "center", templet: function (item) {
                        if (item.noble_id) {
                            return '是';
                        }

                        return '否';
                    }
                },
                {field: '', title: '扣除宝石', width: "105", align: "center", templet: function (item) {
                        if (item.diamond) {
                            return item.diamond;
                        }

                        return '-';
                    }
                },
                {field: '', title: '扣除钻石', width: "105", align: "center", templet: function (item) {
                        if (item.gold) {
                            return item.gold;
                        }

                        return '-';
                    }
                },
                {field: '', title: '购买时间', width: "160", align: "center", templet: function (item) {
                        if (item.created_at) {
                            return item.created_at;
                        }

                        return '-';
                    }
                },
                {field: '', title: '收货人姓名', width: "120", align: "center", templet: function (item) {
                        if (item.user_address && item.user_address.name) {
                            return item.user_address.name;
                        }
                        return '-';
                    }
                },
                {field: '', title: '收货人电话', width: "130", align: "center", templet: function (item) {
                        if (item.user_address && item.user_address.mobile) {
                            return item.user_address.mobile;
                        }
                        return '-';
                    }
                },
                {field: '', title: '收货人地址', width: "170", align: "center", templet: function (item) {
                        if (item.user_address && item.user_address.address) {
                            return item.user_address.address;
                        }
                        return '-';
                    }
                },
                {field: '', title: '状态', width: "100", align: "center", templet: function (item) {
                        if (item.status) {
                            if (item.type == 1) {
                                return '已发放';
                            }

                            return '<font color="red">已发货</font>';
                        }

                        if (item.type == 1) {
                            return '未发放';
                        }

                        return '未发货';
                    }
                },
                {field: '', title: '发放时间', width: "160", align: "center", templet: function (item) {
                        if (item.ship_time) {
                            return item.ship_time;
                        }

                        if (item.status && item.type == 1) {
                            return item.created_at;
                        }

                        return '-';
                    }
                },
                {field: 'express_no', title: '运单号', width: "130", align: "center"},
                {field: 'operator', title: '操作人', width: "150", align: "center", templet: function (item) {
                        if (item.operator) {
                            return item.operator;
                        }
                        return '系统';
                    }
                },
                {
                    title: '操作', align: "center",fixed: 'right', width: "100",templet: function (item) {
                        if (item.status == 0 && item.type == 2) {
                            return '<a class="layui-btn  layui-btn-xs" style="background-color: #1E9FFF" onclick="edit(' + item['id'] + ')"><i class="layui-icon"></i>发货</a>';
                        }
                        return '-';
                    }
                }
            ]],
            done: function (res, curr, count) {
                res.list.forEach(function (item, index) {

                });
            },
        };
    }

    function edit(id) {
        layer.open({
            type: 2,
            title: ["发货", 'font-size:16px'],
            content: '/admin/live_store/order_edit?id=' + id,
            area: ['620px', '590px'],
            //offset: '0px',
        });
    }
</script>
</body>
</html>
